﻿using Himp.Base;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace Himp.Erp.EntityFrameworkCore;

public static class ErpDbContextModelCreatingExtensions
{
    public static void ConfigureErp(
        this ModelBuilder builder)
    {
        Check.NotNull(builder, nameof(builder));

        builder.Entity<BizSeq>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(BizSeq), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        #region 物资基本信息

        builder.Entity<MatlInfo>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(MatlInfo), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<MatlSpler>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(MatlSpler), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<MatlWhse>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(MatlWhse), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        #endregion

        #region 进销存

        builder.Entity<InvChgType>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(InvChgType), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        //入库
        builder.Entity<InboundRec>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(InboundRec), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        //入库明细
        builder.Entity<InboundDetl>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(InboundDetl), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        //物资库存
        builder.Entity<MatlInv>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(MatlInv), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<MaterialAppyRec>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + "MaterialAppyRecs", ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<MaterialAppyDetl>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + "MaterialAppyDetls", ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        //出库
        builder.Entity<OutboundRec>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(OutboundRec), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        //出库明细
        builder.Entity<OutboundDetl>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(OutboundDetl), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        #endregion

        #region 药品

        builder.Entity<DrugCatalogAssocChrgitmType>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(DrugCatalogAssocChrgitmType), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<DrugCatalog>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(DrugCatalog), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<DrugCatalogExt>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(DrugCatalogExt), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<DrugCatalogGrant>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(DrugCatalogGrant), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<DrugCatalogType>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(DrugCatalogType), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<DrugPrdr>(b =>
        {
            b.ToTable(ErpDbProperties.DbTablePrefix + nameof(DrugPrdr), ErpDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        #endregion
    }
}
